package com.xbdun.service.bmp.service.system.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xbdun.dao.bmp.dto.PlatformMenuDto;
import com.xbdun.dao.bmp.mapper.PlatformInfoMapper;
import com.xbdun.dao.bmp.mapper.SysMenuMapper;
import com.xbdun.facade.bmp.request.system.PlatformRequest;
import com.xbdun.facade.bmp.response.system.PlatformMenuResponse;
import com.xbdun.facade.bmp.response.system.PlatformResponse;
import com.xbdun.service.bmp.service.system.PlatfromService;

@Service
public class PlatfromServiceImpl implements PlatfromService{

	@Autowired
	PlatformInfoMapper platformInfoMapper;
	@Autowired
	private SysMenuMapper sysMenuMapper;

	public PlatformResponse getSecretVal(PlatformRequest request) throws Exception {
		PlatformResponse result = null;
		
		String byPlatSecretVal = platformInfoMapper.getByPlatSecretVal(request.getPlatCode());
		if(StringUtils.isNotBlank(byPlatSecretVal)){
			result = new PlatformResponse();
			result.setSecretVal(byPlatSecretVal);
		}
		return result;
	}

	public List<PlatformMenuResponse> getPlatformMenu(int platCode) throws Exception {
		List<PlatformMenuResponse> list = null;
		List<PlatformMenuDto> platformMenu = sysMenuMapper.getPlatformMenu(platCode);
		if(CollectionUtils.isNotEmpty(platformMenu)){
			list = new ArrayList<PlatformMenuResponse>();
			PlatformMenuResponse response = null;
			for(PlatformMenuDto dto : platformMenu){
				response = new PlatformMenuResponse();
				response.setMenuCode(dto.getMenuCode());
				response.setMenuNameHit(dto.getMenuNameHit());
				list.add(response);
			}
		}
		return list;
	}

	public String getSysPlatAuth(String menuKey) {
		return sysMenuMapper.getSysPlatAuth(menuKey);
	}

	public String getCurrentOrgAuth(long orgCode, int platCode) {
		return sysMenuMapper.getCurrentOrgAuth(orgCode,platCode);
	}
}
